﻿using Quartz;
using Quartz.Impl;
using Quartz.Impl.Matchers;

namespace AVCJobDispatcherWindows.TaskJobEngine
{
    public class SchedulerSingleton
    {
        private SchedulerSingleton() { }
        private static IScheduler _schedulerFactory;
        public static IScheduler SchedulerFactory
        {
            get
            {
                //创建调度程序
                if (_schedulerFactory == null)
                {
                    ISchedulerFactory sf = new StdSchedulerFactory();
                    _schedulerFactory = sf.GetScheduler().Result;

                    //添加任务监听
                    _schedulerFactory.ListenerManager.AddJobListener(new JobListener(), GroupMatcher<JobKey>.AnyGroup());
                    _schedulerFactory.ListenerManager.AddTriggerListener(new TriggerListener(), GroupMatcher<TriggerKey>.AnyGroup());
                }
                _schedulerFactory.Start();
                return _schedulerFactory;
            }
        }
    }
}
